// request.js
let common = {
	baseUrl:"https://huishou.68699.cn/app/index.php?i=2&t=0&v=2.7.4&from=wxapp&c=entry&a=wxapp&m=wjyk_recycle",
	header:{
		"Content-Type": "application/json",
		"Content-Type": "application/x-www-form-urlencoded"
	},
	method:"get",
	dataType:"json"
	
}
function request(options = {}) {
    uni.showLoading({
        title: "加载中..."
    });

    options.url = common.baseUrl + options.url;
	// 将 common.data 中的参数合并到 options.data 中
    options.data = { ...options.data, ...common.data };
    options.header = options.header || common.header;
    options.method = options.method || common.method;
    options.dataType = options.dataType || common.dataType;

    return new Promise((resolve, reject) => {
        uni.request({
            ...options,
            success: (result) => {
                if (result.statusCode !== 200) {
                    return reject(result);
                }
                uni.hideLoading();
                let data = result.data;
                resolve(data);
            },
            fail: (error) => {
                reject(error);
            }
        });
    });
}

export default request;
